package com.yearner.reviewplan.manage.system.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yearner.reviewplan.manage.system.entity.UserPerm;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * @author pengyg
 * @since 2020/1/13
 */
@Getter
@Setter
@RequiredArgsConstructor
public class MenuVo {
    private Integer menuId;
    private String title;
    private String perms;
    private Integer type;
    private Integer parentId;
    private String parentName;
    private String path;
    private String icon;
    private Boolean isLock;
    private Integer orderNum;
    private List<MenuVo> children;
    private String creator;
    private String updater;

    public MenuVo(UserPerm perm){
        create(perm, null);
    }
    public MenuVo(UserPerm perm, String parentName) {
        create(perm, parentName);
    }

    private void create(UserPerm perm, String parentName) {
        this.menuId = perm.getPermId();
        this.title = perm.getTitle();
        this.perms = perm.getPermName();
        this.parentId = perm.getParentId();
        this.type = Integer.valueOf(perm.getPermType());
        if (this.type == 1) {
            this.path = perm.getUrl();
        }
        this.icon = perm.getIcon();
        this.isLock = perm.getILock();
        this.parentName = parentName;
        this.orderNum = perm.getSort();
        this.creator = perm.getCreator();
        this.updater = perm.getUpdater();
    }
    @JsonIgnore
    public UserPerm getUserPerm() {
        UserPerm perm = new UserPerm();
        perm.setPermId(this.menuId);
        perm.setTitle(this.title);
        perm.setParentId(this.parentId);
        perm.setPermName(this.perms);
        perm.setPermType(this.type.byteValue());
        perm.setUrl(this.path);
        perm.setIcon(this.icon);
        perm.setILock(this.isLock);
        perm.setSort(this.orderNum);
        perm.setCreator(this.creator);
        perm.setUpdater(this.updater);
        return perm;
    }
}
